// 注册业务
const btnRegister = document.querySelector('#btn-register')
console.log(btnRegister);

const form = document.querySelector('.register-form')
btnRegister.addEventListener('click', async function () {
    // console.log(11);

    const data = serialize(form, { hash: true, empty: true })
    // const { username, password } = data
    if (data.username.length < 8 || data.username.length > 30) {
        return showToast('用户名是8-30位')
    }
    if (data.password.length < 6 || data.password.length > 30) {
        return showToast('密码是6-30位')
    }
    //提交用户名和密码到服务器
    // const { data: { message } } = await axios.post('/register', data)
    try {
        const { data: { message } } = await axios({
            url: '/register',
            method: 'post',
            data: {
                username: data.username,
                password: data.password
            }
        })
        // console.log(res);

        //提示
        showToast(message)
    } catch (err) {
        console.dir(err);

    }
})
